package servlet.recipe.page;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import mysql.JdbcUtil;
import servlet.recipe.control.Recipe_rsp;

import java.io.IOException;
@WebServlet("/Recipe")
public class InRecipe extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String checkValue=req.getParameter("style");
        String recipe_id=req.getParameter("recipe_id");
        JdbcUtil jdbu=new JdbcUtil();
        if (jdbu.checkNotNull(checkValue)) {
            req.getRequestDispatcher("chushi/jsp/recipe.jsp").forward(req, resp);
        }
        checkValue=req.getParameter("recipe_name");
        if (jdbu.checkNotNull(checkValue)){
            req.setAttribute("title",checkValue);
            Recipe_rsp rsq=new Recipe_rsp();
            req.setAttribute("recipes",rsq.recipes_rsp(4,recipe_id));
        }

        req.getRequestDispatcher("chushi/jsp/recipe.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
